Configuration and Programming
Below are some pieces of advice that may help you configure and use the live binding properly:
- If operations need to be performed together, they must be assigned to the same binding group and invoked on the group. Let’s describe the wrong approach first: When the user presses a button, you want to grab values from several controls on the form, and write them to various OPC items. You configure the WriteEventSource on each binding to the Click event of the Button. Well, while this “kind of” works, it is very ineffective approach, because each binding will be handled separately, and the OPC writes will be executed one by one, sequentially. The proper approach is to create a binding group for this purpose, set all bindings involved in the “write” to be members of this binding group, and then set the WriteEventSource just once, on the binding group itself. This way, the binding group will attempt to write all values into their corresponding OPC items using a single call with multiple items in it.
- Remember to always set the BindingExtender back to offline mode. This guideline only applies if you are controlling the BindingExtender-s Online property in a way that differs from the default described in How the Binding Extender Automatically Goes Online and Offline. In such case, you need to be aware that while the BindingExtender is online mode, there are event handlers set up that may prevent the normal application shutdown. Basically, by setting the Online property of BindingExtender to 'true', you indicate that for whatever reason, you are interested in being connected to the binding targets – and you have to explicitly set it back to false in order to indicate that this is no longer needed.
Combination with Imperative Programming Model
For more advanced tasks, you may want to combine the Live Binding model with the Imperative Programming Model. Such combination is perfectly possible and supported.
When doing so, consider the fact that Live Binding uses its own, "isolated" client objects (such as EasyDAClient or EasyUAClient). When you create instances of the client objects in your own code, your code will have separate connections (sessions) from those used in the Live Binding. This may be fine, but can cause issues in some cases (e.g. when the target OPC Server is an embedded server with limited number of concurrent sessions).
In order to prevent this from happening, you can "borrow" the client object from the Live Binding, and use it in your code. To do so, call the GetClient methods on the DAConnectivity or UAConnectivity component that you already have for the Live Binding. The method returns an IEasyDAClient (or IEasyUAClient) interface, and you can use it to perform any necessary operations through imperative programming.
See Also